package com.group.yztcedu.playlive.main.me.View;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.group.yztcedu.playlive.R;
import com.group.yztcedu.playlive.bean.MyDataBean;
import com.group.yztcedu.playlive.main.me.precenter.IMyActivityPrecenter;
import com.group.yztcedu.playlive.main.me.precenter.MyActivityPresenter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MeFollowActivity extends AppCompatActivity implements IMeActivity {

    @BindView(R.id.me_follow_refresh)
    SwipeRefreshLayout meFollowRefresh;

    @BindView(R.id.me_follow_back)
    ImageView meFollowBack;
    @BindView(R.id.me_follow_list)
    ListView meFollowList;

    private IMyActivityPrecenter presenter;
    private String sqlurl = "select * from user";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_follow);
        ButterKnife.bind(this);

        //设置下拉出现小圆圈是否是缩放出现，出现的位置，最大的下拉位置
        meFollowRefresh.setProgressViewOffset(true, 50, 200);
//设置下拉圆圈的大小，两个值 LARGE， DEFAULT
        meFollowRefresh.setSize(SwipeRefreshLayout.DEFAULT);
// 设置下拉圆圈上的颜色，蓝色、绿色、橙色、红色
        meFollowRefresh.setColorSchemeResources(
                android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

// 通过 setEnabled(false) 禁用下拉刷新
        meFollowRefresh.setEnabled(true);

// 设定下拉圆圈的背景
// .setProgressBackgroundColor(R.color.red);
/*
 * 设置手势下拉刷新的监听
 */
        meFollowRefresh.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        // 刷新动画开始后回调到此方法
                        initData();
                    }
                }
        );

    }

    public void initData() {
        presenter = new MyActivityPresenter(this);
        presenter.initData(sqlurl, getApplicationContext());
    }

    @Override
    public void LodeData(List<MyDataBean> list) {
        meFollowRefresh.setRefreshing(false);
        MyAdapter adapter = new MyAdapter(list,getApplicationContext());
        meFollowList.setAdapter(adapter);
        if(list.size()==0){
            Toast.makeText(getApplicationContext(),"没有关注！",Toast.LENGTH_SHORT).show();

        }else{
            adapter.notifyDataSetChanged();
        }

    }

    @OnClick({R.id.me_follow_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.me_follow_back:
                finish();
                break;
        }
    }
}
